#include "SQLDeclareStatement.h"

#include "../SQLName.h"
#include "../SQLDataType.h"
#include "../SQLExpr.h"

#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../../../utils/log.h"
#include "../SQLDeclareItem.h"
#include "SQLColumnConstraint.h"

SQLDeclareStatement::SQLDeclareStatement()
{
  items = std::make_shared<std::list<std::shared_ptr<SQLDeclareItem>>>();
}

SQLDeclareStatement::SQLDeclareStatement(SQLName_ptr name, SQLDataType_ptr dataType)
{
  items = std::make_shared<std::list<std::shared_ptr<SQLDeclareItem>>>();
  this->addItem(std::shared_ptr<SQLDeclareItem>(new SQLDeclareItem(name, dataType)));
}

SQLDeclareStatement::SQLDeclareStatement(SQLName_ptr name, SQLDataType_ptr dataType, SQLExpr_ptr value)
{
  items = std::make_shared<std::list<std::shared_ptr<SQLDeclareItem>>>();
  this->addItem(std::shared_ptr<SQLDeclareItem>(new SQLDeclareItem(name, dataType, value)));
}

void SQLDeclareStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLDeclareStatement)))
  {
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLDeclareItem, SQLObject>(items);
    this->acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLDeclareStatement));
}

SQLDeclareItem_list_ptr SQLDeclareStatement::getItems()
{
  return items;
}

void SQLDeclareStatement::addItem(std::shared_ptr<SQLDeclareItem> item)
{
  if (item != NULL)
  {
    item->setParent(SharedObject(SQLDeclareStatement));
  }
  this->items->push_back(item);
}
